﻿/**
 * 栏目管理
 * 
 * @author liuxl
 * @createTime 2010-11-25
 */
Ext.ux.CategoryPanel = function() {
	// alert(src.windowId);
	var desktop = MyDesktop.getDesktop();
	var winV = desktop.getWindow('category-view-win');

	var cId = 0;
	var cName = null;
	if (!winV) {

		var index = 0;
		winV = desktop.createWindow({
			id : 'category-view-win',
			title : '栏目管理',
			closable : true,
			modal : 'true',
			width : 900,
			height : 560,
			layout : "border",
			items : [{
				id : 'category-panel',
				region : 'west',
				layout : 'accordion',
				split : true,
				width : 170,
				minSize : 175,
				maxSize : 400,
				collapsible : true,
				margins : '5 0 5 5',
				layoutConfig : {
					animate : true,
					sequence : true
				},
				tbar : [{
							text : '一级类别排序',
							iconCls : 'icon-plugin',
							icon : 'static/images/desktop/icons/fam/cog_edit.png',
							handler : function() {
								var grid1 = null;
								try {
												Ext.Ajax.request({
													url : "static/js/ext/ux/Ext.ux.CPanel.js",
													async : false,
													success : function(request) {
														try {
															eval(request.responseText);
															var cPanelEntity = eval("Ext.ux.CPanel('0');");
															grid1 = cPanelEntity.getGrid();
														} catch (e) {
															alert(e);
														}
													}
												});
											} catch (e) {

												alert(e);
											}
							
								
								Ext.getCmp('categoryPanel').add({
											title : '一级类别',
											id : 'firstC',
											iconCls : 'tabs',
											layout : 'fit',
											items : grid1,
											closable : true
										}).show();
								grid1.store.load({
											params : {
												start : 0,
												limit : 100
											},
											callback : listError
										});

							}

						}],
				items : [{
					title : '子级栏目管理',
					items : [{

						xtype : 'treepanel',
						id : 'categoryTree2',
						border : false,
						rootVisible : true,
						autoScroll : true,
						loader : new Ext.tree.TreeLoader({
							dataUrl : 'admin/category.jhtml?method=getFirstCategoryTree'
						}),
						root : new Ext.tree.AsyncTreeNode({
									id : "root",
									text : "子级栏目管理"
								}),
						listeners : {

							'click' : function(n) {
								try {
									var sn = this.selModel.selNode || {};
									if (n.leaf && n.id != sn.id) {
										var categoryId = n.id;
										var tab = Ext.getCmp('categoryPanel')
												.getComponent(categoryId + 'c');
										if (tab) {
											Ext.getCmp('categoryPanel')
													.setActiveTab(tab);
										} else {
											
											var grid1 = null;
											try {
												Ext.Ajax.request({
													url : "static/js/ext/ux/Ext.ux.CPanel.js",
													async : false,
													success : function(request) {
														try {
															eval(request.responseText);
															var cPanelEntity = eval("Ext.ux.CPanel("+categoryId+");");
															grid1 = cPanelEntity.getGrid();
														} catch (e) {
															alert(e);
														}
													}
												});
											} catch (e) {

												alert(e);
											}
											Ext.getCmp('categoryPanel').add({
														title : n.text + ' 栏目 ',
														id : categoryId + 'c',
														iconCls : 'tabs',
														layout : 'fit',
														items : grid1,
														closable : true
													}).show();

											grid1.store.load({
														params : {
															start : 0,
															limit : 100,
															categoryId : categoryId
														},
														callback : listError
													});
										}
									}
								} catch (e) {
								}
							}

						}

					}]
				}]
			}, {
				xtype : 'tabpanel',
				id : 'categoryPanel',
				region : 'center',
				activeItem : 0,
				resizeTabs : true,
				enableTabScroll : true,
				border : false,
				plugins : new Ext.ux.TabCloseMenu(),
				items : [getStartPanel('categoryStart')]
			}]
		});

	}
	winV.show();

}